<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt"%>
<%
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ request.getContextPath();
%>
<!DOCTYPE html>
<html lang="en">
<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8">
		<link rel="stylesheet" type="text/css" href="<%=basePath %>/css/updateVideo.css" />
		<link rel="stylesheet" href="<%=basePath %>css/list.css">
		<link href="<%=basePath %>css/H-ui.min.css" rel="stylesheet" type="text/css" />
		<link href="<%=basePath %>/css/H-ui.min.css" rel="stylesheet" type="text/css" />
		<link href="<%=basePath %>/css/formsCSS.css" rel="stylesheet" type="text/css" />
		<!-- select start -->
		<link href="<%=basePath %>/lib/bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
		<link href="<%=basePath %>/css/multiple-select.css" rel="stylesheet" type="text/css" /> 
		<!-- select end -->
		
		<script src="<%=basePath %>/js/jquery.min.js"></script>
		<script src="<%=basePath %>/js/formsJS.js"></script>
		<!-- kindeditor富文本编辑器 -->
		<link href="<%=basePath%>/kindeditor/themes/default/default.css">
		<link href="<%=basePath%>/kindeditor/plugins/code/prettify.css">
		<script src="<%=basePath%>/kindeditor/lang/zh-CN.js"></script>
		<script src="<%=basePath%>/kindeditor/kindeditor-all.js"></script>
		
		 <script src="<%=basePath%>/js/multiple-select.js"></script> 
		
<script type="text/javascript">

function checkForm(f){

	if(f.courseName.value.replace(/\s/g,'') == ''){
		alert("课程名称不能为空");
		return false;
	}
	/* if(f.courseCount.value.replace(/\s/g,'') == ''){
		alert("课程数量不能为空");
		return false;
	} */
	if(f.chapterCount.value.replace(/\s/g,'') == ''){
		alert("章节数量不能为空");
		return false;
	}
	if(f.courseType.value.replace(/\s/g,'') == ''){
		alert("课程分类不能为空");
		return false;
	}
	
	if(f.speakerId.value.replace(/\s/g,'') == ''){
		alert("主讲人不能为空");
		return false;
	}
	if(f.courseDuration.value.replace(/\s/g,'') == ''){
		alert("课程时长不能为空");
		return false;
	}
	if(f.orderNum.value.replace(/\s/g,'') == ''){
		alert("课程排序不能为空");
		return false;
	}
	if(f.newFlag.value.replace(/\s/g,'') == ''){
		alert("是否最新课程不能为空");
		return false;
	}
	if(f.allow_recharge.value.replace(/\s/g,'') == ''){
		alert("是否允许返铜钱不能为空");
		return false;
	}
 
	return true;
}

</script>
</head>
<body>
		<div class="connect_wrap">
    		<h3 style= "text-align: center;">课程信息维护</h3>
			<div class="row cl" style="max-width:88%;margin-left:8%;">
			<div class="labelText"></div>
				<form action="<%=basePath%>/courseInfo/courseInfoEdit" method="post" onsubmit="return checkForm(this)"
					enctype="multipart/form-data">
				<div class="col-sm-4"></div>
    					<div class="col-sm-4">
   							<div class="boxs">
									<input type="hidden" name="id" value="${CourseInfo.id}">
									<input type="hidden" name="courseCategoryId" value="${CourseInfo.courseCategoryId}" id="courseCategoryId">
									<input type="text" class="inputBox" placeholder="课程名称" name="courseName" value="${CourseInfo.courseName}" >
									<input type="text" class="inputBox" placeholder="课程原价" name="orignalPrice" value="${CourseInfo.orignalPrice}" >
									<input type="text" class="inputBox" placeholder="课程活动价" name="activityPrice" value="${CourseInfo.activityPrice}" >
									<input type="text" class="inputBox" placeholder="章节数量" name="chapterCount" value="${CourseInfo.chapterCount}" >
									<select class="selectBox" name="speakerId" id="speakerId">
				    				<option value="">----请选择主讲人----</option>
					    			<c:forEach items="${speakers}" var="p">
					    				<option value="${p.id}" ${p.id == CourseInfo.speakerId ? 'selected="selected"' : ''}>${p.id}:${p.speakerName}</option>
					    			</c:forEach>
		    						</select>
		    						<%-- <select class="selectBox" name="goodsId" id="goodsId">
					    				<option value="">----请选择赠送商品----</option>
						    			<c:forEach items="${goods}" var="g">
						    				<option value="${g.id}" ${g.id == CourseInfo.goodsId ? 'selected="selected"' : ''}>${g.id}:${g.goodsName}</option>
						    			</c:forEach>
		    						</select>
		    						<input type="text" class="inputBox" placeholder="课程商品组合价" name="combinedPrice" value="${CourseInfo.combinedPrice}" > --%>
									<select id="courseType" name="courseType" class="selectBox"  >
									  	<option value="">课程类型</option>
									  	<option value="1" ${CourseInfo.courseType == 1 ? 'selected="selected"' : '' }>免费</option>
							  			<option value="2" ${CourseInfo.courseType == 2 ? 'selected="selected"' : '' }>付费</option>
									</select>
									<select id="newFlag" name="newFlag" class="selectBox"  >
									  	<option value="">是否新课程</option>
							  			<option value="0" ${CourseInfo.newFlag == 0 ? 'selected="selected"' : '' }>否</option>
							  			<option value="1" ${CourseInfo.newFlag == 1 ? 'selected="selected"' : '' }>是</option>
									</select>
									<select id="courseStatus" name="courseStatus" class="selectBox"  >
									  	<option value="">课程状态</option>
							  			<option value="1" ${CourseInfo.courseStatus == 1 ? 'selected="selected"' : '' }>上线</option>
							  			<option value="2" ${CourseInfo.courseStatus == 2 ? 'selected="selected"' : '' }>下线</option>
									</select>

									<div class="labelText" style="position: relative; top: 20px; left: 0px; color: rgb(154, 144, 144);">课程推荐分类</div>

									<div style="width:90%;margin-top:30px">
										<select id="cId" name="cId" multiple="multiple" >
											<c:forEach items="${coures}" var="p">
												<option value="${p.id}" >${p.id}:${p.name}</option>
											</c:forEach>
										</select>
									</div>
									
									<div class="labelText" style="position: relative; top: 20px; left: 0px; color: rgb(154, 144, 144);">返铜钱活动设置</div>
									<select id="allow_recharge" name="allow_recharge" class="selectBox"  >
									  	<option value="">是否允许返铜钱</option>
							  			<option value="1" ${CourseInfo.allow_recharge == 1 ? 'selected="selected"' : '' }>允许</option>
							  			<option value="2" ${CourseInfo.allow_recharge == 2 ? 'selected="selected"' : '' }>不允许</option>
									</select>
									
									 <input type="number" class="inputBox" name="orderNum"  value="${CourseInfo.orderNum}" placeholder="课程排序"><br />
									 <input type="file" class="inputBox" name="courseFile"  value="${CourseInfo.courseImgUrl}" placeholder="课程广告图片"><br />
									<%-- <input type="text" class="inputBox" placeholder="课程数量" name="courseCount" value="${CourseInfo.courseCount}" > --%>
									<input type="text" class="inputBox" placeholder="课程时长" name="courseDuration" value="${CourseInfo.courseDuration}" >
									<input type="text" class="inputBox" placeholder="课程简介" name="courseDesc" value="${CourseInfo.courseDesc}" ><br>
										<br>
										<textarea  id="courseDetails" placeholder="课程详情" name="courseDetails" class="inputBox kindeditor" style="width: 90%;">${CourseInfo.courseDetails}</textarea>
									 
									
									<input type="submit" value="确定" class="true" />
									<input type="button"  class="false" value="取消" onclick="window.history.go(-1)">
								</div>
							</div>
					</form>
			</div>
	</div>
</body>
<script type="text/javascript">

var editor;
	KindEditor.ready(function(K) {
		
	    editor = K.create('#courseDetails', {
	            uploadJson : '<%=basePath%>/kindeditor/upload',       
	            fillDescAfterUploadImage: false,
	            allowImageRemote:false,
	            afterCreate : function() {
	                var self = this;
	                K.ctrl(document, 13, function() {
	                    self.sync();
	                });
	                K.ctrl(self.edit.doc, 13, function() {
	                    self.sync();
	                });
	            },
	            afterBlur:function(){ 
	                this.sync(); 
	            } 
	        });
	});  
</script>	
	<script>
    $(function() {
        $('#cId').multipleSelect({
            width: '100%'
        });
    });
    $(function(){
    	//加载适用范围
    	var v = $("#courseCategoryId").val();
    		var w = v.split(',');
    		$("#cId").multipleSelect("setSelects",w).change(function() {
            	$("#courseCategoryId").val($(this).val());
            	var v = $("#courseCategoryId").val();
            });    		
    	
    });
    </script>
</html>